import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * 小票类
 */
class Receipt {
    private Date timestamp;           // 交易时间
    private ArrayList<Item> items;    // 商品列表
    private double total;            // 总金额
    private String paymentMethod;    // 支付方式
    private String memberNo;         // 会员卡号

    public Receipt(Date timestamp, ArrayList<Item> items, double total, String paymentMethod) {
        this.timestamp = timestamp;
        this.items = new ArrayList<>(items);
        this.total = total;
        this.paymentMethod = paymentMethod;
    }

    // Getter方法
    public Date getTimestamp() { return timestamp; }
    public ArrayList<Item> getItems() { return items; }
    public double getTotal() { return total; }
    public String getPaymentMethod() { return paymentMethod; }
    public String getMemberNo() { return memberNo; }

    // Setter方法
    public void setMemberNo(String memberNo) { this.memberNo = memberNo; }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("===== 超市购物小票 =====\n");
        sb.append("时间: ").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp)).append("\n");
        sb.append("----------------------\n");

        for (Item item : items) {
            sb.append(String.format("%s\t%s\t%.2f × %d\t= %.2f\n",
                    item.getCode(),
                    item.getName(),
                    item.getPrice(),
                    item.getQuantity(),
                    item.getPrice() * item.getQuantity()));
        }

        sb.append("----------------------\n");
        sb.append(String.format("总计: ¥%.2f\n", total));
        sb.append("支付方式: ").append(paymentMethod).append("\n");
        sb.append("======================\n");
        return sb.toString();
    }
}

